/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: RxProcessEnginePlugin
 * @Package com.rx.camunda.plugin
 * @Description: 插件
 * @author: 陈锦韬
 * @date: 2021\8\13 0013
 * @version V1.0
 * @Copyright: 2021 陈锦韬  All rights reserved.
 */
package com.rx.camunda.plugin;

import com.rx.core.enm.RX_LOG_MODE;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin;
import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

/**
 * @author: Administrator
 * @Description: 插件
 * @date: 2021\8\13 0013
 */
@Slf4j
@Component
public class RxProcessEnginePlugin implements ProcessEnginePlugin {
    @Override
    public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
        log.info(RX_LOG_MODE.DEFAULT.getFormat("{}"),"流程插件","前初始化");
        // 优化.因为源码是MYSQL 它需要连数据库确认
        processEngineConfiguration.setDatabaseType("mysql");
        // 开启定时器
        processEngineConfiguration.setJobExecutorActivate(true);
        // 工作流不做权限判断
        processEngineConfiguration.setAuthorizationEnabled(false);


        Resource[] resources = ((SpringProcessEngineConfiguration)processEngineConfiguration).getDeploymentResources();

        ((SpringProcessEngineConfiguration)processEngineConfiguration).setDeploymentResources(resources);
    }

    @Override
    public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
        log.info(RX_LOG_MODE.DEFAULT.getFormat("{}"),"流程插件","后初始化");
    }

    @Override
    public void postProcessEngineBuild(ProcessEngine processEngine) {
        log.info(RX_LOG_MODE.DEFAULT.getFormat("{}"),"流程插件","引擎创建完成");
    }
}
